/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxMoves = function (grid) {
  let m = grid.length, n = grid[0].length, res = 0
  function traver(count, row, col) {
    if (row >= 1 && col < n - 2) {
      if (grid[row - 1][col + 1] > grid[row][col]) {
        traver(count + 1, row - 1, col + 1)
      }
    }

    if (grid[row][col + 1] > grid[row][col]) {
      traver(count + 1, row, col + 1)
    }

    if (grid[row + 1][col + 1] > grid[row][col]) {
      traver(count + 1, row + 1, col + 1)
    }
  }

  traver(res, 0, 0)
  return res

};
// maxMoves([[2, 4, 3, 5], [5, 4, 9, 3], [3, 4, 2, 11], [10, 9, 13, 15]])


var compose = function (functions) {

  return function (x) {
    let res = x
    for (let i = functions.length - 1; i >= 0; i--) {
      res = functions[i](res)
    }
    return res
  }
};

compose([x => x + 1, x => x * x, x => 2 * x])(4)